<template>
  <div class="app-container home">
    <div class="bg_fff p_10 listbody">
      <div class="flexrowbetween flexwrapper" style="align-items: flex-start">
        <div class="flex">
          <div
            class="iconbox flexcenter commhover mr_10"
            @click="resetQuery"
          >
            <i class="el-icon-refresh f-20" :class="{ rotate: isrefresh }"></i>
          </div>
          <!-- <el-button plain type="primary" size="mini" @click="handleAdd"
            >添加</el-button
          > -->
          <el-button
            plain
            type="danger"
            :disabled="multiple"
            size="mini"
            @click="handleDelete"
            >删除</el-button
          >
        </div>
        <div>
          <el-form
            :model="queryParams"
            ref="queryForm"
            size="small"
            :inline="true"
            label-width="0"
          >
            <!-- <el-form-item prop="name">
              <el-input
                class="searchinput"
                v-model="queryParams.name"
                placeholder="请输入投诉内容"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item> -->
            <el-form-item prop="type">
              <el-select v-model="queryParams.type" clearable placeholder="投诉类型" @change="handleQuery">
                <el-option label="功能异常" :value="1" />
                <el-option label="产品建议" :value="2" />
              </el-select>
            </el-form-item>
            <el-form-item class="mr_0">
              <el-dropdown trigger="click">
                <el-button size="mini" class="nor_border plr_9">
                  <svg-icon class-name="f-14" icon-class="listicon" />
                  <i class="el-icon-caret-bottom el-icon--right"></i>
                  <!-- <i class="el-icon-s-fold f-14"></i> -->
                </el-button>
                <el-dropdown-menu slot="dropdown">
                  <div class="dropbody">
                    <el-checkbox-group
                      v-model="checkedOption"
                      class="flexcolumn"
                      @change="changeSelect"
                    >
                      <el-checkbox
                        v-for="(item, index) in selectoptions"
                        :label="item.label"
                        :key="index"
                        class="m_5"
                        >{{ item.label }}</el-checkbox
                      >
                    </el-checkbox-group>
                  </div>
                </el-dropdown-menu>
              </el-dropdown>
            </el-form-item>
            <!-- <el-form-item>
              <el-dropdown trigger="click" @command="handleCommand">
                <el-button size="mini" class="nol_border plr_9">
                  <svg-icon class-name="f-14" icon-class="export" />
                  <i class="el-icon-caret-bottom el-icon--right"></i>
                </el-button>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item
                    v-for="(item, index) in exportlist"
                    :key="index"
                    :command="item.id"
                    >{{ item.name }}</el-dropdown-item
                  >
                </el-dropdown-menu>
              </el-dropdown>
            </el-form-item> -->
            <el-form-item>
              <el-button
                class="f-14"
                icon="el-icon-search"
                size="mini"
                @click="handleQuery"
              ></el-button>
            </el-form-item>
          </el-form>
        </div>
      </div>
      <el-table
        v-loading="loading"
        :data="tableData"
        border
        ref="tablelayout"
        class="commtable"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55"></el-table-column>
        <el-table-column
          v-if="complainOption.includes('平台')"
          align="center"
          label="平台"
          prop="id"
          width="120"
        >
          <template slot-scope="scope">
            {{ scope.row.task?scope.row.task.tp_name:'-'}} 
          </template>
        </el-table-column>
        <el-table-column
          v-if="complainOption.includes('活动ID')"
          align="center"
          label="活动ID"
          prop="name"
        >
          <template slot-scope="scope">
            <span v-if="scope.task">{{scope.row.task.tp_id}}</span>
            <span v-else>-</span>
          </template>
        </el-table-column>
        <el-table-column
          v-if="complainOption.includes('活动分类')"
          align="center"
          label="活动分类"
          prop="name"
        >
          <template slot-scope="scope">
            <span v-if="scope.task">{{ scope.row.task.template.template_class?scope.row.task.template.template_class.name:'-' }} </span>
            <span v-else>-</span>
          </template>
        </el-table-column>
        <el-table-column
          v-if="complainOption.includes('活动名称')"
          align="center"
          label="活动名称"
          prop="name"
        >
          <template slot-scope="scope">
            <span v-if="scope.task">{{scope.row.task.name}}</span>
            <span v-else>-</span>
          </template>
        </el-table-column>
        <el-table-column
          v-if="complainOption.includes('活动编号')"
          align="center"
          label="活动编号"
          prop="name"
        >
          <template slot-scope="scope">
            <span v-if="scope.task">{{scope.row.task.id}}</span>
            <span v-else>-</span>
          </template>
        </el-table-column>
        <el-table-column
          v-if="complainOption.includes('活动时间')"
          align="center"
          label="活动时间"
          prop="name"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.task">{{ scope.row.task.draw_startime }} - {{scope.row.task.draw_endtime}}</span>
            <span v-else></span>
          </template>
        </el-table-column>
        <el-table-column
          v-if="complainOption.includes('投诉类型')"
          align="center"
          label="投诉类型"
          prop="name"
        >
          <template slot-scope="scope">
            <span>{{scope.row.type == 1?'功能异常':'产品建议'}}</span>
          </template>
        </el-table-column>
        <el-table-column
          v-if="complainOption.includes('投诉内容')"
          align="center"
          label="投诉内容"
          prop="name"
        >
          <template slot-scope="scope">
            <span>{{scope.row.msg||'-'}}</span>
          </template>
        </el-table-column>
        <el-table-column
          v-if="complainOption.includes('联系电话')"
          align="center"
          label="联系电话"
          prop="name"
        >
          <template slot-scope="scope">
            <span>{{scope.row.phone||'-'}}</span>
          </template>
        </el-table-column>
        <el-table-column
          v-if="complainOption.includes('备注')"
          align="center"
          label="备注"
          prop="name"
        >
          <template slot-scope="scope">
            <span>{{scope.row.beizhu||'-'}}</span>
          </template>
        </el-table-column>
        <el-table-column
          v-if="complainOption.includes('投诉时间')"
          align="center"
          label="投诉时间"
          prop="create_time"
        ></el-table-column>
        <el-table-column
          prop="created_at"
          label="操作"
          width="220"
          fixed="right"
          align="center"
        >
          <template slot-scope="scope">
            <div class="flex btnflex">
              <!-- <div
                class="commhover btn_green c_fff mr_10"
                @click="handleUpdate(scope.row)"
              >
                <i class="el-icon-edit f-14"></i>拖动
              </div> -->
              <div
                class="commhover btn_green c_fff mr_10"
                @click="handleUpdate(scope.row)"
              >
                <i class="el-icon-edit f-14"></i> 编辑
              </div>
              <div
                class="commhover btn_yellow c_fff"
                @click="handleDelete(scope.row)"
              >
                <i class="el-icon-delete f-14"></i> 删除
              </div>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.page"
        :limit.sync="queryParams.num"
        @pagination="getList"
      />
    </div>
    <el-dialog
      :title="title"
      :visible.sync="open"
      width="680px"
      class="dialogheaderbg"
      :before-close="handleCloseAdd"
      :close-on-click-modal='false'
    >
      <edit-complain v-if="open" :row="row" @close="handleCloseAdd" />
    </el-dialog>
  </div>
</template>

<script>
import { mapState } from "vuex";
import { getComplainIndex,complainDel } from '@/api/compain'
import EditComplain from './EditComplain.vue';
export default {
  data() {
    return {
      queryParams: {
        page: 1,
        num: 10,
        name: undefined,
      },
      total: 1,
      loading: false,
      tableData: [],
      checkedOption: [],
      isrefresh: false,
      selectoptions: [
        { id: 1, label: "平台" },
        { id: 2, label: "活动ID" },
        { id: 3, label: "活动分类" },
        { id: 4, label: "活动名称" },
        { id: 5, label: "活动编号" },
        { id: 6, label: "活动时间" },
        { id: 7, label: "投诉类型" },
        { id: 8, label: "投诉内容" },
        { id: 9, label: "联系电话" },
        { id: 10, label: "备注" },
        { id: 11, label: "投诉时间" },
      ],
      dialogAddVisible: false,
      multiple: true,
      title: "",
      // 是否显示弹出层
      open: false,
      row: "",
    };
  },

  props: {
    type: {
      type: Number,
      default: 1,
    },
  },

  components:{
    EditComplain
  },

  computed: {
    ...mapState({
      complainOption: (state) => state.paramsoption.complainOption,
    }),
  },

  created() {
    let complainOption = JSON.parse(localStorage.getItem("complainOption"));
    if (complainOption) {
      this.changeSelect(complainOption);
    }
    this.checkedOption = this.complainOption;
    this.getList()
  },

  methods: {
    getList() {
      this.loading = true;
      let params = {
        page:this.queryParams.page,
        num:this.queryParams.num
       };
      if(this.queryParams.type){
        params.type = this.queryParams.type
      }
      getComplainIndex(params).then((response) => {
        this.tableData = response.data.list;
        this.total = response.data.count;
        this.loading = false;
      });
      this.isrefresh = false;
      this.loading = false;
    },

    handleQuery() {
      this.queryParams.page = 1;
      this.getList();
    },

    changeSelect(arr) {
      this.$store.commit("SET_COMPLAINOPTION", arr);
      this.$nextTick(() => {
        //在数据加载完，重新渲染表格
        this.$refs.tablelayout && this.$refs.tablelayout.doLayout();
      });
    },

    resetQuery() {
      this.isrefresh = true;
      this.resetForm("queryForm");
      this.handleQuery();
    },

    handleSelectionChange(selection) {
      this.rowids = selection.map((item) => item.id);
      this.multiple = !selection.length;
    },

    handleCloseAdd(type) {
      if (type == 1) {
        this.getList();
      }
      this.open = false;
    },

    handleCommand(command) {
      console.log(command);
    },

    /** 修改按钮操作 */
    handleUpdate(row) {
      this.row = row;
      this.open = true;
      this.title = "修改";
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      const infoIds = row.id || this.rowids;
      this.$modal
        .confirm('是否确认删除访问编号为"' + infoIds + '"的数据项？')
        .then(function () {
          return complainDel({id:infoIds});
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
  },
};
</script>

<style lang="scss" scoped>
.iconbox {
  width: 32px;
  height: 32px;
  border: 1px solid #eee;
  border-radius: 2px;
}
.imgbox {
  width: 100px;
  height: 40px;
}
</style>
